package com.farewell.blog.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.farewell.blog.entity.QueryBean;
import com.farewell.blog.entity.SearchResource;
import com.farewell.blog.mapper.ResourceListMapper;
import com.farewell.blog.pojo.ResourceList;
import com.farewell.blog.service.ResourceListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Farewell
 * @date 2021/3/4
 */
@Service
public class ResourceListServiceImpl implements ResourceListService {
    @Autowired
    private ResourceListMapper resourceListMapper;

    @Override
    public Page<ResourceList> listResourceListByCondition(SearchResource searchResource, QueryBean queryBean) {
        Page<ResourceList> pageData = new Page<>(queryBean.getCurrentPage(), queryBean.getPageSize());
        List<ResourceList> resourceLists = resourceListMapper.getResourcesBySearch(pageData, searchResource);
        pageData.setRecords(resourceLists);
        return pageData;
    }

    @Override
    public Page<ResourceList> listResourceList(QueryBean queryBean) {
        Page<ResourceList> pageData = new Page<>(queryBean.getCurrentPage(), queryBean.getPageSize());
        List<ResourceList> resourceLists = resourceListMapper.listResourceList(pageData);
        pageData.setRecords(resourceLists);
        return pageData;
    }

    @Override
    public List<ResourceList> getAllResourceList() {
        return resourceListMapper.getAllResourceList();
    }

    @Override
    public void addResourceList(ResourceList resourceList) {
        resourceListMapper.insert(resourceList);
    }

    @Override
    public void updateResourceList(ResourceList resourceList) {
        resourceListMapper.updateAllColumnById(resourceList);
    }

    @Override
    public void deleteResourceList(Long id) {
        resourceListMapper.deleteById(id);
    }
}
